package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.LogDAO;
import com.swlz.entity.Log;
import com.swlz.exception.CodeException;
import com.swlz.service.LogService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 系统操作日志
 * ClassName : com.swlz.service.impl.LogServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-26 08:22:01
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class LogServiceImpl implements LogService {
	
	private LogDAO logDAO = new LogDAO();

	@Override
	public int add(Log log) throws CodeException {
		try {
			return logDAO.insertSelective(log);
		} catch (SQLException e) {
			throw new CodeException(500, "添加系统操作日志错误",e);
		}
	}

	@Override
	public int update(Log log) throws CodeException {
		try {
			return logDAO.updateSelective(log);
		} catch (SQLException e) {
			throw new CodeException(501, "修改系统操作日志错误",e);
		}
	}

	@Override
	public int delete(Long logId) throws CodeException {
		try {
			return logDAO.deleteById(logId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除系统操作日志错误",e);
		}
	}

	@Override
	public Log get(Long logId) throws CodeException {
		try {
			return logDAO.selectById(logId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取系统操作日志失败",e);
		}
	}

	@Override
	public PageVO<Log> page(Log log, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = logDAO.countByModel(log);
			PageVO<Log> page = new PageVO<>(total, current, rowMax);
			return page.setList(logDAO.selectByModel(log, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取系统操作日志分页数据失败",e);
		}
	}


}
